namespace DingHeng.TransportationManagement.Entity
{
    using System;
    using System.Data.Entity;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;

    public partial class TransportationManagementContext : DbContext
    {
        public TransportationManagementContext()
            : base("name=TransportationManagementContext")
        {
        }

        public virtual DbSet<Authority> Authorities { get; set; }
        public virtual DbSet<DictionaryData> DictionaryDatas { get; set; }
        public virtual DbSet<Driver> Drivers { get; set; }
        public virtual DbSet<Function> Functions { get; set; }
        public virtual DbSet<Permission> Permissions { get; set; }
        public virtual DbSet<Role> Roles { get; set; }
        public virtual DbSet<TransportationForm> TransportationForms { get; set; }
        public virtual DbSet<TransportationLog> TransportationLogs { get; set; }
        public virtual DbSet<User> Users { get; set; }
        public virtual DbSet<Vehicle> Vehicles { get; set; }
        public virtual DbSet<VehicleDispatchForm> VehicleDispatchForms { get; set; }
        public virtual DbSet<VehicleOwner> VehicleOwners { get; set; }
        public virtual DbSet<VehicleRegister> VehicleRegisters { get; set; }
        public virtual DbSet<VehicleDispatchFormInfo> VehicleDispatchFormInfoes { get; set; }
        public virtual DbSet<VehicleInfo> VehicleInfoes { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<DictionaryData>()
                .Property(e => e.Code)
                .IsUnicode(false);

            modelBuilder.Entity<DictionaryData>()
                .Property(e => e.Type)
                .IsUnicode(false);

            modelBuilder.Entity<Driver>()
                .Property(e => e.PhoneNo)
                .IsUnicode(false);

            modelBuilder.Entity<Driver>()
                .Property(e => e.IDNo)
                .IsUnicode(false);

            modelBuilder.Entity<Driver>()
                .Property(e => e.DrivingLicense)
                .IsUnicode(false);

            modelBuilder.Entity<Function>()
                .Property(e => e.Code)
                .IsUnicode(false);

            modelBuilder.Entity<Role>()
                .Property(e => e.Code)
                .IsUnicode(false);

            modelBuilder.Entity<TransportationForm>()
                .Property(e => e.LoadTotalQuantity)
                .HasPrecision(8, 3);

            modelBuilder.Entity<TransportationForm>()
                .Property(e => e.LoadVehicleQuantity)
                .HasPrecision(8, 3);

            modelBuilder.Entity<TransportationForm>()
                .Property(e => e.LoadQuantity)
                .HasPrecision(8, 3);

            modelBuilder.Entity<TransportationForm>()
                .Property(e => e.UnloadTotalQuantity)
                .HasPrecision(8, 3);

            modelBuilder.Entity<TransportationForm>()
                .Property(e => e.UnloadVehicleQuantity)
                .HasPrecision(8, 3);

            modelBuilder.Entity<TransportationForm>()
                .Property(e => e.UnloadQuantity)
                .HasPrecision(8, 3);

            modelBuilder.Entity<TransportationForm>()
                .Property(e => e.Duration)
                .HasPrecision(8, 3);

            modelBuilder.Entity<TransportationForm>()
                .Property(e => e.LoadUserName)
                .IsUnicode(true);

            modelBuilder.Entity<TransportationForm>()
                .Property(e => e.UnloadUserName)
                .IsUnicode(true);

            modelBuilder.Entity<TransportationLog>()
                .Property(e => e.TotalWeight)
                .HasPrecision(8, 3);

            modelBuilder.Entity<TransportationLog>()
                .Property(e => e.VehicleWeight)
                .HasPrecision(8, 3);

            modelBuilder.Entity<TransportationLog>()
                .Property(e => e.NetWeight)
                .HasPrecision(8, 3);

            modelBuilder.Entity<User>()
                .Property(e => e.PhoneNo)
                .IsUnicode(false);

            modelBuilder.Entity<User>()
                .Property(e => e.Account)
                .IsUnicode(false);

            modelBuilder.Entity<User>()
                .Property(e => e.Password)
                .IsUnicode(false);

            modelBuilder.Entity<User>()
                .Property(e => e.Code)
                .IsUnicode(false);

            modelBuilder.Entity<Vehicle>()
                .Property(e => e.RateLoad)
                .HasPrecision(8, 3);

            modelBuilder.Entity<VehicleDispatchForm>()
                .Property(e => e.Code)
                .IsUnicode(false);

            modelBuilder.Entity<VehicleDispatchForm>()
                .Property(e => e.ContactNo)
                .IsUnicode(false);

            modelBuilder.Entity<VehicleDispatchForm>()
                .Property(e => e.DriverContactNo)
                .IsUnicode(false);

            modelBuilder.Entity<VehicleDispatchForm>()
                .Property(e => e.VehicleOwnerContactNo)
                .IsUnicode(false);

            modelBuilder.Entity<VehicleDispatchForm>()
                .HasMany(e => e.TransportationForms)
                .WithOptional(e => e.VehicleDispatchForm)
                .HasForeignKey(e => e.VehicleDispatchID);

            modelBuilder.Entity<VehicleDispatchForm>()
                .HasMany(e => e.TransportationLogs)
                .WithOptional(e => e.VehicleDispatchForm)
                .HasForeignKey(e => e.VehicleDispatchID);

            modelBuilder.Entity<VehicleOwner>()
                .Property(e => e.ContactNo)
                .IsUnicode(false);

            modelBuilder.Entity<VehicleOwner>()
                .HasMany(e => e.Vehicles)
                .WithOptional(e => e.VehicleOwner)
                .HasForeignKey(e => e.OwnerID);

            modelBuilder.Entity<VehicleRegister>()
                .Property(e => e.Code)
                .IsUnicode(false);

            modelBuilder.Entity<VehicleDispatchFormInfo>()
                .Property(e => e.Code)
                .IsUnicode(false);

            modelBuilder.Entity<VehicleDispatchFormInfo>()
                .Property(e => e.DriverContactNo)
                .IsUnicode(false);

            modelBuilder.Entity<VehicleDispatchFormInfo>()
                .Property(e => e.VehicleOwnerContactNo)
                .IsUnicode(false);

            modelBuilder.Entity<VehicleDispatchFormInfo>()
                .Property(e => e.VehicleCode)
                .IsUnicode(false);

            modelBuilder.Entity<VehicleInfo>()
                .Property(e => e.RateLoad)
                .HasPrecision(8, 3);

            modelBuilder.Entity<VehicleInfo>()
                .Property(e => e.DriverPhoneNo)
                .IsUnicode(false);

            modelBuilder.Entity<VehicleInfo>()
                .Property(e => e.DriverIDNo)
                .IsUnicode(false);

            modelBuilder.Entity<VehicleInfo>()
                .Property(e => e.OwnerContactNo)
                .IsUnicode(false);

            modelBuilder.Entity<VehicleInfo>()
                .Property(e => e.Code)
                .IsUnicode(false);
        }
    }
}
